package com.example.teaching_server.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 年级班级简略信息DTO
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "年级班级简略信息")
public class GradeClassSimpleDTO {

    @NotBlank(message = "显示名称不能为空")
    @Schema(description = "组合显示名称（年级+班级）", example = "一年级一班", requiredMode = Schema.RequiredMode.REQUIRED)
    private String displayName;

    @NotNull(message = "班级ID不能为空")
    @Positive(message = "班级ID必须是正整数")
    @Schema(description = "班级唯一标识", example = "101", requiredMode = Schema.RequiredMode.REQUIRED)
    private Long classId;

    @NotNull(message = "年级ID不能为空")
    @Positive(message = "年级ID必须是正整数")
    @Schema(description = "年级唯一标识", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
    private Long gradeId;

    /**
     * 获取年级名称（从displayName中提取）
     */
    @Schema(description = "年级名称", accessMode = Schema.AccessMode.READ_ONLY)
    public String getGradeName() {
        if (displayName != null && displayName.length() >= 3) {
            return displayName.substring(0, 2); // 假设前两个字符是年级
        }
        return displayName;
    }

    /**
     * 获取班级名称（从displayName中提取）
     */
    @Schema(description = "班级名称", accessMode = Schema.AccessMode.READ_ONLY)
    public String getClassName() {
        if (displayName != null && displayName.length() >= 3) {
            return displayName.substring(2); // 假设第三个字符开始是班级
        }
        return displayName;
    }

    /**
     * 获取简写标识符
     */
    @Schema(description = "简写标识符", accessMode = Schema.AccessMode.READ_ONLY)
    public String getShortIdentifier() {
        return "G" + gradeId + "C" + classId;
    }

    /**
     * 验证显示名称格式（基础验证）
     */
    public boolean isValidDisplayName() {
        return displayName != null && displayName.length() >= 3 &&
                displayName.matches(".*[一二三四五六七八九十]年级.*");
    }
}
